<template>
  <div id="app">
    <header class="mui-bar mui-bar-nav">
      <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
      <h1 class="mui-title">我的拼团</h1>
    </header>
    <div class="mui-content">
      <div class="top_nav">
        <div :class="i.status==now_nav_index?' top_nav_item active':' top_nav_item ' " v-for="(i,k) in top_nav"
             @click="change_nav(i.status)" :key="k">
          <span v-html="i.name"></span>
        </div>
        <!--<div class="top_nav_item" @click="get_data(2)">
                  <span>待发货</span>
              </div>
              <div class="top_nav_item" @click="get_data(3)">
                  <span>待收货</span>

              </div>
              <div class="top_nav_item" @click="get_data(4)">
              <span>已完成</span>
              </div>-->
      </div>
      <div class="top_bg"></div>
      <div class="mui-scroll-wrapper">
        <div class="mui-scroll">
          <ul class="mui-table-view">
            <li class="mui-table-view-cell" v-for="(daifas, index) in list" :key="index">
              <div class="order_list_info_top">
                <div class="order_list_info_top_text">社区商城</div>
                <div class="order_list_info_top_state"> {{daifas|status_to_name}}</div>
              </div>
              <div class="order_list_info_container" @click="open_order_detail_view(daifas,true)">
                <div class="order_list_info_container_img">
                  <img :src="daifas.pic"/>
                </div>
                <div class="order_list_info_container_right">
                  <div class="order_list_info_container_right_text">{{daifas.goodsname}}</div>
                  <div class="order_list_info_container_right_num">X {{daifas.num}}</div>
                  <div class="order_list_info_container_right_price">￥{{daifas.money}}</div>
                </div>
              </div>
              <div class="order_list_info_bottom">
                <div class="order_list_info_bottom_productNum">共{{daifas.num}}件商品</div>
                <div class="order_list_info_bottom_productAdd">合计</div>
                <div class="order_list_info_bottom_productPic">￥{{daifas.money}}</div>
                <div class="order_list_info_bottom_productBtn">
                  <div @tap="to_pay(daifas.order_no,daifas.sid)" v-show="daifas.status==1"
                       class="order_list_info_bottom_productBtn_right order_list_info_bottom_productBtn_one">
                    去付款
                  </div>


                  <div @tap="open_share_group_view(true,daifas.orderid,daifas.sid)" v-show="daifas.status==2&&daifas.s_status==0"
                       class="order_list_info_bottom_productBtn_right order_list_info_bottom_productBtn_one">
                    分享拼团
                  </div>


                  <div v-show="daifas.status==1&&daifas.s_status==0"
                       class="order_list_info_bottom_productBtn_right order_list_info_bottom_productBtn_one"
                       @tap="del_order(daifas.orderid)">取消订单
                  </div>

                  <div v-show="daifas.status==3"
                       class="order_list_info_bottom_productBtn_right order_list_info_bottom_productBtn_one"
                       @tap="confirm_order(daifas.orderid)">确认收货
                  </div>
                  <div v-show="daifas.status==4"
                       class="order_list_info_bottom_productBtn_right order_list_info_bottom_productBtn_one"
                       @tap="pinglun(index)">评价
                  </div>
                </div>
              </div>
            </li>

          </ul>

        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import h5_plus from "../../tools/h5_plus"
  import goods_ajax from "../../ajax/goods_ajax";

  export default {
    name: 'collage',
    data() {
      return {
        now_nav_index: 1,
        top_nav: [
          {
            name: '拼团中',
            status: '1'
          },
          {
            name: '待付款',
            status: '2'
          },
          {
            name: '拼团成功',
            status: '3'
          },
          {
            name: '拼团失败',
            status: '4'
          }
        ],
        list: [],				//订单数据
      };
    },
    filters: {
      status_to_name(order) {

        /*
                status  1    s_status 0       代付款
                status  2    s_status 0       拼团中
                status  2    s_status 1       拼团成功
                status  2    s_status -1      拼团失败
                */

        if (order.status == 1 && order.s_status == 0) {
          return "待付款"
        }

        if (order.status == 2 && order.s_status == 0) {
          return "还差人" + order.sheng + "拼团成功"
        }

        if (order.status == 2 && order.s_status == 1) {
          return "拼团成功 待发货"
        }

        if (order.status == 3 && order.s_status == 1) {
          return "拼团成功 已发货"
        }

        if (order.status == 2 && order.s_status == -1) {
          return "拼团失败"
        }
      }
    },
    methods: {
      //订单路由
      onderurl: function (url, val) {
        this.$router.push({path: url, query: {queryId: val}});
      },
      to_pay(order_num,sid) {
        console.log("去支付")
        console.log(order_num)

        // 发起支付
        h5_plus.pay_fun(order_num, res => {
          this.$router.push("/")
          this.$store.commit("open_pay_succ_view", true)
        })
      },
      open_order_detail_view(order,tf){
        console.log("order",order);
        this.$store.commit("updata_open_order_detail_view",tf);
        this.$store.commit("updata_order_info",order);
      },
      open_share_group_view(tf, orderid,sid) {
        // 获取分享商品信息
        goods_ajax.get_share_group_goods_info({
          orderid
        }, res => {
          this.$store.commit("updata_share_group_goods_info", res);
          this.$store.commit("updata_share_group_type", 'share');
          this.$store.commit("updata_share_group_sid",{
            sid:sid,
            orderid:orderid
          })
          this.$store.commit("open_share_group_view", tf)
        })

      },
      change_nav: function (i) {
        this.now_nav_index = i;
        this.$axios.get("api/spell/userdefaults", {
          params: {
            uid: this.$store.state.account.user_info.uid,
            type: i
          }
        }).then(res => {
          this.list = res.data;
          console.log(res);
        });
      }
    },
    mounted() {
      //this.$axios
//		this.$axios.get("https://zhapp.4hl.cn/api/spell/userdefault?uid=3&type="+this.$route.query.queryId).then(res=>{
//			this.list = res.data
//		    console.log(res);
//		});
      this.$axios.get("api/spell/userdefaults", {
        params: {
          uid: this.$store.state.account.user_info.uid,
          type: this.$route.query.queryId
        }
      }).then(res => {
        this.list = res.data
        console.log(res);
      });
      this.now_nav_index = this.$route.query.queryId
    },
    components: {}
  }
</script>
<style lang="less" scoped>
  @import "../../../static/pxvalue.less";
  @import "../../assets/less/my/order_list.less";
  @import "../../assets/less/my/order.less";
</style>
